package com.mt.lulucai;

import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
import android.content.res.Resources;

import com.facebook.stetho.Stetho;
import com.mt.lulucai.usbdriver.help.GlobalVariable;
import com.mt.lulucai.constant.Constant;
import com.mt.lulucai.runtime.PreferenceHelper;
import com.mt.lulucai.runtime.RT;
import com.mt.lulucai.util.ProcessUtil;
import com.squareup.leakcanary.RefWatcher;
import com.watch.StrictModeWrapper;

import java.util.Locale;

/**
 * Created by daiguangtao on 17/4/20.
 */

public class LuLuCaiApplication extends Application {

    private RefWatcher refWatcher;
    // 初始化数据
    private GlobalVariable mGlobalVariable;

    public static RefWatcher getRefWatcher(Context context) {
        LuLuCaiApplication application = (LuLuCaiApplication) context.getApplicationContext();
        return application.refWatcher;
    }

    private static boolean strictModeAvailable;

    @Override
    public void onCreate() {
        super.onCreate();

        // 多进程情况只初始化一次
        if (ProcessUtil.isCurMainProcess(getApplicationContext())) {


            Constant.DEBUG = BuildConfig.DEBUG;

            if (strictModeAvailable) {
                int applicationFlags = getApplicationInfo().flags;
                if (BuildConfig.DEBUG && ((applicationFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0)) {
                    StrictModeWrapper.enableDefaults();
                }
            }
            RT.application = this;
            Stetho.initialize(
                    Stetho.newInitializerBuilder(this)
                            .enableDumpapp(
                                    Stetho.defaultDumperPluginsProvider(this))
                            .enableWebKitInspector(
                                    Stetho.defaultInspectorModulesProvider(this))
                            .build());

            RT.lastbleid = PreferenceHelper.ins().getStringShareData(Constant.KEY_LAST_BLE,"empty");

        }
        getDatas();
    }

    //退出app
    public void exit() {
        android.os.Process.killProcess(android.os.Process.myPid());
        System.exit(0);
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }
    // 初始化数据
    private void getDatas() {
        mGlobalVariable = GlobalVariable.getinstance();
    }




    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }
}
